package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.result.Result;
import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.VO.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.VO.BorrowerDetailVO;
import com.atguigu.srb.core.pojo.VO.BorrowerVO;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author ZLHao
 * @since 2021-07-12
 */
@Api(tags = "借款人管理")
@Slf4j
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

    @Autowired
    private BorrowerService borrowerService;

    @ApiOperation("分页列表")
    @GetMapping("/list/{page}/{limit}")
    public Result listPage(@PathVariable Long page ,@PathVariable Long limit,@RequestParam String keyword){

        Page<Borrower> borrowerPage = new Page<>(page,limit);
        IPage<Borrower> pageModel =  borrowerService.listPage(borrowerPage,keyword);
        return Result.ok().data("pageModel",pageModel);

    }


    /**
     * @description: 显示借款人的详细信息
     * @param: id
     * @return: com.atguigu.common.result.Result
     * @author Administrator
     * @date: 2021/7/20 0020 23:16
     */
    @GetMapping("/show/{id}")
    public Result  show(@PathVariable Long id){

     BorrowerDetailVO borrowerDetailVO =  borrowerService.getBorrowerDetailVOById(id);

     return Result.ok().data("borrowerDetailVO",borrowerDetailVO);

    }


    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public Result approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO) {
        borrowerService.approval(borrowerApprovalVO);
        return Result.ok().message("审批完成");
    }


}

